package com.heima.controller;

import com.heima.common.PageResult;
import com.heima.pojo.Partner;
import com.heima.pojo.dto.PartnerDTO;
import com.heima.pojo.dto.PartnerPageQueryDTO;
import com.heima.pojo.vo.PartnerVo;
import com.heima.service.PartnerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    @Autowired
    private PartnerService partnerService;
    @PostMapping
    public Boolean save(@RequestBody PartnerDTO partnerDTO){
        log.info("新增合作商：{}",partnerDTO);
        partnerService.save(partnerDTO);
        return true;
    }

    /**
     * 合作商分页查询
     * @param partnerPageQueryDTO
     * @return
     */
    @GetMapping("/search")
    public PageResult pageQuery(PartnerPageQueryDTO partnerPageQueryDTO){
        PageResult pageResult = partnerService.pageQuery(partnerPageQueryDTO);
        return pageResult;
    }

    @GetMapping("/{id}")
    public PartnerVo selectById(@PathVariable Long id){
        PartnerVo partnerVo = partnerService.selectById(id);
        return partnerVo;
    }

    @PutMapping("/{id}")
    public Boolean update(@PathVariable Long id,@RequestBody Partner partner){
        partnerService.update(id,partner);
        return true;
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Long id){
        partnerService.delete(id);
        return true;
    }
}
